/*
 * DevEAT123A.c
 *
 * Created: 30.12.2013 09:10:27
 *  Author: Simon
 */ 

#include "DevEAT123A.h"

void DevEAT123A_init(void)					/* Initialisierung LCD */
{
	i2c_start(0x74);			// Start with Slave- Adress
	_delay_ms (1.0);
	i2c_write(0x00);			// Send Control Byte
	_delay_ms (1.0);
	i2c_write(0x2E);			// Funktion Set
	_delay_ms (1.0);
	i2c_write(0x01);			// Clear Display
	_delay_ms (1.0);
	i2c_write(0x0E);			// Display on/off control
	_delay_ms (1.0);
	i2c_write(0x06);			// 	Entry mode set
	
	//i2c_stop();
}

int display_outstring(char *outtext)
{
	unsigned char length = strlen(outtext);
	unsigned char count;
	unsigned char count2;

	i2c_start(0x74);
	_delay_ms (1.0);
	i2c_write(0x40);

	if (length>12)
	length+=6;
	if (length>=24)
	length+=6;

	for (count=0; count < length; count++)
	{
		if (count<12)
		{
			count2=count;
			i2c_write(outtext[count2] +0x80);
			_delay_ms (1.0);
		}
	}
	i2c_stop();
	return 0;
}

void DevEAT123A_write(char *outtext, int line)
{
	switch (line)
	{
		case 1:
		i2c_start(DevEAT123A);
		i2c_write(0x00);
		i2c_write(0x80);
		display_outstring(outtext);
		break;
		case 2:
		i2c_start(DevEAT123A);
		i2c_write(0x00);
		i2c_write(0xA0);
		display_outstring(outtext);
		break;
		case 3:
		i2c_start(DevEAT123A);
		i2c_write(0x00);
		i2c_write(0xC0);
		display_outstring(outtext);
		break;
		default:
		i2c_start(DevEAT123A);
		i2c_write(0xA0);
		i2c_write(0x80);
		display_outstring("Wrong Line");
		break;
	}
	
}


